﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HotelManagement._04.OBJECT;
using HotelManagement._03.DAO;
using HotelManagement._02.BUS;

namespace HotelManagement._01.FORM
{
    public partial class F12_ChangePassword : Form
    {
        public F12_ChangePassword()
        {
            InitializeComponent();
        }
        User m_User=new User();
        UserBUS m_UserBUS =new UserBUS();
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnChange_Click(object sender, EventArgs e)
        {
            if (m_UserBUS.ViewUserById(AssetsGS.instance.UserId).Rows.Count > 0)
            {
                m_User.UserID = AssetsGS.instance.UserId;

                string v_Password = m_UserBUS.ViewUserById(AssetsGS.instance.UserId).Rows[0]["Password"].ToString();
                if (v_Password != m_txt_CurPassword.Text)
                {
                    MessageBox.Show("Mật khẫu cũ không đúng !");
                    return;
                }
            }
            if (m_txt_ConfirmPassword.Text != m_txt_NewPassword.Text)
            {
                MessageBox.Show("Mật khẩu xác nhận không đúng !");
                return;
            }
            else
            {
                m_User.Password = m_txt_NewPassword.Text;
                try
                {
                    if (m_UserBUS.UpdatePassword(m_User)) MessageBox.Show("Sửa mật khẩu thành công");
                }
                catch (Exception v_e)
                {
                    throw v_e;
                }
            }            
        }


    }
}
